var class_num=location.search;
class_num=class_num.split('?')[1];
$('#href_homework').attr('href','homework.html?'+class_num);
$('#href_course').attr('href','course.html?'+class_num);
$('#href_file').attr('href','file.html?'+class_num);
$('#href_index').attr('href','course.html?'+class_num);
$('#href_message').attr('href','message.html?'+class_num);
$('#me').attr('href','me.html?'+class_num);
if (islogin()) {
    $.post({
        url: '../../requests/student/select_progress.php',
        data: {'class_num': class_num},
        async: false,
        success: function (data) {
            $('#c-bar').LineProgressbar({
                percentage: data * 100,
                ShowProgressCount: true,
                fillBackgroundColor: '#0894ec',
                backgroundColor: '#f7f7f8',
            });
        }
    });

    $.post({
        url:'../../requests/student/courses.php',
        data:{'class':class_num},
        success:function (data) {
            if (data == 'error') {
                $$.alert('错误！',function () {
                    window.location.href='../../index.html';
                });
            }
            else {
                for (var i = 0; i < data.length; i++) {
                    if (data[i].taken == 1) {
                        var dom1 = "<div class='card'>" +
                            "<div class='card-header taken'>" +
                            "<div>第<span class='sec_num'>" + data[i].num + "</span>章&nbsp<span class='sec_name'>" + data[i].name + "</span>" +
                            "</div>" +
                            "</div>" +     //结束card-header
                            "<div class='card-content'>" +
                            "<div class='card-content-inner'>";
                    }
                    else {
                        var dom1 = "<div class='card'>" +
                            "<div class='card-header'>" +
                            "<div>第<span class='sec_num'>" + data[i].num + "</span>章&nbsp<span class='sec_name'>" + data[i].name + "</span>" +
                            "</div>" +
                            "</div>" +     //结束card-header
                            "<div class='card-content'>" +
                            "<div class='card-content-inner'>";
                    }
                    if (typeof (data[i].sub) != 'undefined') {
                        for (var j = 0; j < data[i].sub.length; j++) {
                            if (data[i].sub[j].taken == 1) {
                                var dom1 = dom1 + "<div class='item-inner'>" +
                                    "<div class='item-content taken'>第<span class='sub_num'>" + data[i].sub[j].num + "</span>节&nbsp<span class='sub_name'>" + data[i].sub[j].name + "</span></div>" +
                                    "</div>";
                            }
                            else {
                                var dom1 = dom1 + "<div class='item-inner'>" +
                                    "<div class='item-content'>第<span class='sub_num'>" + data[i].sub[j].num + "</span>节&nbsp<span class='sub_name'>" + data[i].sub[j].name + "</span></div>" +
                                    "</div>";
                            }
                        }
                        var dom2 = "</div></div></div>";
                        $('.course_list').append(dom1 + dom2);
                    }
                    else {
                        var dom2 = "</div></div></div>";
                        $('.course_list').append(dom1 + dom2);
                    }

                }
            }

        }
    });
}
else window.location.href='../../index.html';
